<template>
  <div class="scroll">
    <div class="location">
      <div class="top">
        <span class="title">定位城市</span>
        <router-link to="/home" class="back">返回首页</router-link>
      </div>
      <div class="city city1">
        <span>定位失败，请稍后重试</span>
      </div>
    </div>
    <div class="visit">
      <span class="title">最近访问城市</span>
      <div class="city city2">
        <span>安庆</span>
        <span>上海</span>
        <span>鞍山</span>
      </div>
    </div>
    <div class="hotCity">
      <span class="title">热门城市</span>
      <div class="city city2">
        <span>上海</span>
        <span>北京</span>
        <span>广州</span>
        <span>深圳</span>
        <span>武汉</span>
        <span>天津</span>
        <span>西安</span>
        <span>南京</span>
        <span>杭州</span>
        <span>成都</span>
        <span>重庆</span>
      </div>
    </div>
    <van-index-bar class="word">
      <template v-for="(item, index) in city">
        <van-index-anchor :key="index" :index="item.initial" />
        <van-cell
          v-for="(i, ikey) in item.list"
          :key="index + '-' + ikey"
          :title="i.name"
          style="background: #f5f5f5"
        />
      </template>
    </van-index-bar>
  </div>
</template>

<script>
export default {
  name: "City",
  data() {
    return {
      city: [],
    };
  },
  created() {
    this.$axios.get("/city.json").then((res) => {
      this.city = res.data.city;
    });
  },
};
</script>

<style scoped>
.scroll {
  overflow: scroll;
}
.top {
  display: flex;
  justify-content: space-between;
  background-color: #ebebeb;
}
.top .back {
  height: 0.8rem;
  padding-right: 0.4rem;
  line-height: 0.8rem;
  color: red;
  font-weight: bold;
}
.title {
  display: block;
  background: #ebebeb;
  height: 0.8rem;
  padding-left: 0.4rem;
  line-height: 0.8rem;
}

.location,
.hotCity,
.visit {
  font-size: 0.385rem;
}

.city {
  background: #f5f5f5;
  padding-right: 0.8rem;
  padding-bottom: 0.213rem;
}

.city span {
  display: inline-block;
  background: white;
  height: 30px;
  line-height: 30px;
}

.word {
  background: #ebebeb;
}

.city span,
.city span,
.city span {
  border: 1px solid #e6e6e6;
  margin-top: 0.4rem;
  margin-left: 0.373rem;
}

.city1 span {
  padding-left: 0.533rem;
  padding-right: 0.533rem;
}

.city2 span {
  width: 2.4rem;
  text-align: center;
  padding: 0 0.107rem;
}
</style>
